< previous page page_129 next page >

Page 129
EXERCISE
1. Double-click the VarType(str) command button to see the following code, which sets the module-level variable mvntVar to a String data type:
Private Sub cmdVarStr_Click ()
mvntVar = "Hi There"

lblVarStr.Caption = VarType(mvntVar)
End Sub
2. Note the following output when this code is run:
8
3. Double-click the VarType(int) command button to see the following code, which changes the module-level variable to a numeric data type:
Private Sub cmdVarInt_Click ()
mvntVar = 10

lblVarInt.Caption = VarType(mvntVar)
End Sub
4. Note the following output when this code is run:
2

Empty Variants
When a variant variable is first declared using Dim, Public, Private, or any other scope, its initially assigned an Empty value. This is a special value that indicates nothing has been assigned to the variable since it was declared. The built-in Visual Basic function IsEmpty() returns True if the variable contains an Empty value and False if it does not. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim vntTemp As Variant
...

If IsEmpty(vntTemp) Then
     vntTemp = "Bill Gates"
End If

 
< previous page page_129 next page >

If you like this book, buy it!